Component({
  partialUpdate: true,
  mixins: [],
  props: {
    turntable: "", // 转盘内容
    turntableBtn: "", // 按钮属性
    prizeInfo: "", // 转盘奖品对应位置
    prizeIndex: null, // 转盘奖品对应位置
    lotteryCount: 0 // 抽奖次数
  },
  data: {
    rotate: 0, // 旋转的角度
    transitionTime: 5, // 转动的时间
    lapCount: 8, // 转动的圈数
    prizeIndex: null, // 奖品下标
    animationTiming: 'ease' // 动画速度
  },
  didMount() {
    this.flag = true;
    this.setData({
      prizeIndex: this.props.prizeIndex
    })
  },
  didUpdate(prevProps, prevData) {
    if (this.props.prizeIndex != this.data.prizeIndex && !this.flag) {
      this.setData({ prizeIndex: this.props.prizeIndex });
      this.runingFn()
    }

  },
  didUnmount() { },
  methods: {
    // 点击按钮
    clickFn() {
      if (this.props.lotteryCount <= 0) {
        this.props.onFinish({ msg: '没有抽奖次数了哦！', count: 0 });
        return;
      }
      if (!this.flag) {
        // this.props.onFinish({ msg: "请不要重复点击哦", code: 200 });
        console.log({ msg: "请不要重复点击哦", code: 200 });
        return;
      };
      this.flag = false;

      // this.setData({
      //   rotate: 360 + parseInt(this.data.rotate),
      // });
      this.props.onStart();
    },
    // 旋转角度
    runingFn(index) {
      if(this.data.prizeIndex == null) return;

      this.setData({
        rotate: 360 * this.data.lapCount + this.props.prizeInfo[this.data.prizeIndex].angle,
        transitionTime: 5,
      }, () => {

        setTimeout(() => {
          // console.log(this.data.prizeIndex);
          this.setData({
            rotate: this.props.prizeInfo[this.data.prizeIndex].angle,
            transitionTime: 0
          }, () => {

            setTimeout(() => {
              this.flag = true;
              this.props.onFinish(this.props.prizeInfo[this.data.prizeIndex])
              this.setData({ transitionTime: 5, prizeIndex: null, animationTiming: 'ease' })

            }, 10);

          })
        }, 5200);

      })
    },
  },
});
